package com.h.web.controller;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.h.common.entity.Commodity;
import com.h.sevice.CommodityService;
import com.pandawork.core.exception.SSException;
import com.pandawork.core.log.LogClerk;
import com.pandawork.core.web.spring.controller.Base;

@Controller
@RequestMapping(value = "/buy")
public class BuyController extends Base {
	
	@Autowired
	@Qualifier("commodityService")
    private static CommodityService commodityService;
	
	/**
	 * 添加购买商品
	 * @param num
	 * @return
	 */
	@RequestMapping(value="/{num}/add",method=RequestMethod.GET)
	public @ResponseBody void addCommodity(@PathVariable Integer num){
		try {
			Commodity commodity = commodityService.findCommodityByNum(num);
			JSONObject obj = new JSONObject();
			obj.put("commodity", commodity);
			print(obj);
		} catch (SSException e) {
			LogClerk.errLog.error(e);
			sendErrMsg(e.getMessage());
		}
	}
}
